#include "GameMenuScene.h"

#include "TYBase.h"
#include "TYController.h"

GameMenuScene::GameMenuScene(void)
{
}

GameMenuScene::~GameMenuScene(void)
{
}

bool GameMenuScene::init ()
{
	bool bRet = false;
	
	do
	{
		CCSize s = CCDirector::sharedDirector()->getWinSize();
		CC_BREAK_IF(!CCScene::init());

		/*
		TYLayerBackGround* backLayer = TYLayerBackGround::layerWithFile(s_backgroud_menu_image);
		CC_BREAK_IF(!backLayer);
		this->addChild(backLayer,0);
		*/

		GameMenuLayer* layer = GameMenuLayer::node();
		CC_BREAK_IF(!layer);
		this->addChild(layer, 1);

		bRet = true;

	}while(0);

	return bRet;
}

void GameMenuLayer::onEnter()
{
	TYLayerMenu::onEnter();
}



void GameMenuLayer::onExit()
{
	TYLayerMenu::onExit();
}

GameMenuLayer::GameMenuLayer()
{

}

GameMenuLayer::~GameMenuLayer()
{

}

bool GameMenuLayer::init ()
{
	bool bRet = false;
	
	do 
	{
		CCSize s = CCDirector::sharedDirector ()->getWinSize ();

		//CC_BREAK_IF(!CCLayerColor::initWithColorWidthHeight (ccc4(0, 0, 0, 255), s.width, s.height));
		CC_BREAK_IF(!TYLayer::init());
				
		CCLabelBMFont* label = CCLabelBMFont::labelWithString(g_gamemenus[GameStart].c_str(), s_fontmenu);
		CC_BREAK_IF(!label);
		CCMenuItemLabel* startLabel = CCMenuItemLabel::itemWithLabel(label, this, menu_selector(GameMenuLayer::MenuItemCallBack));
		CC_BREAK_IF(!startLabel);
		startLabel->setTag(GameStart);
		startLabel->setPosition(ccp(s.width/2,s.height/2+120));

		CCLabelBMFont* labelGuid = CCLabelBMFont::labelWithString(g_gamemenus[GameGuide].c_str(), s_fontmenu);
		CC_BREAK_IF(!labelGuid);
		CCMenuItemLabel* guidLabel = CCMenuItemLabel::itemWithLabel(labelGuid, this, menu_selector(GameMenuLayer::MenuItemCallBack));
		CC_BREAK_IF(!guidLabel);
		guidLabel->setTag(GameGuide);
		guidLabel->setPosition(ccp(s.width/2,s.height/2+60));

		CCLabelBMFont* labelSetting = CCLabelBMFont::labelWithString(g_gamemenus[GameSetting].c_str(), s_fontmenu);
		CC_BREAK_IF(!labelSetting);
		CCMenuItemLabel* settingLabel = CCMenuItemLabel::itemWithLabel(labelSetting, this, menu_selector(GameMenuLayer::MenuItemCallBack));
		CC_BREAK_IF(!settingLabel);
		settingLabel->setTag(GameSetting);
		settingLabel->setPosition(ccp(s.width/2,s.height/2));

		CCLabelBMFont* labelPoint = CCLabelBMFont::labelWithString(g_gamemenus[GamePoint].c_str(), s_fontmenu);
		CC_BREAK_IF(!labelPoint);
		CCMenuItemLabel* pointLabel = CCMenuItemLabel::itemWithLabel(labelPoint, this, menu_selector(GameMenuLayer::MenuItemCallBack));
		CC_BREAK_IF(!pointLabel);
		pointLabel->setTag(GamePoint);
		pointLabel->setPosition(ccp(s.width/2,s.height/2-60));

		CCLabelBMFont* labelExit = CCLabelBMFont::labelWithString(g_gamemenus[GameExit].c_str(), s_fontmenu);
		CC_BREAK_IF(!labelExit);
		CCMenuItemLabel* exitLabel = CCMenuItemLabel::itemWithLabel(labelExit, this, menu_selector(GameMenuLayer::MenuItemCallBack));
		CC_BREAK_IF(!exitLabel);
		exitLabel->setTag(GameExit);
		exitLabel->setPosition(ccp(s.width/2,s.height/2-120));


		CCMenu* menu=CCMenu::menuWithItems(startLabel,guidLabel,settingLabel,pointLabel,exitLabel,NULL);
		menu->setPosition(CCPointZero);
		menu->setScale(g_fLabelScale);


		this->addChild(menu,1);
	
		bRet = true;

	} while (0);

	return bRet;
}

void GameMenuLayer::MenuItemCallBack ( CCObject* sender )
{
	CCMenuItemLabel* tempMenuLabel = (CCMenuItemLabel*)sender;
	if (!tempMenuLabel)
	{
		return;
	}

	switch (tempMenuLabel->getTag())
	{
	case GameStart:
		TYController::ShowMethodSelectScene ();
		break;
	case GameGuide:
		break;
	case GameSetting:
		break;
	case GamePoint:
		break;
	case GameExit:
		SimpleAudioEngine::sharedEngine()->end();
		CCDirector::sharedDirector()->end();
		break;
	}
}
